import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:ytbusiness/config/style.dart';
import 'package:ytbusiness/config/yt_theme.dart';
import 'package:ytbusiness/page/auto_makers/shop_home/order_details/order_info.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/widgets/widgets.dart';

///待报价
class WaitingOffer extends StatefulWidget {
  @override
  _WaitingOfferState createState() => _WaitingOfferState();
}

class _WaitingOfferState extends State<WaitingOffer> {
  List<String> typeList = ["原厂原包", "品牌", "拆车", "OEM"];
  bool isShow = false;//默认隐藏
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () {
        //输入框失焦
        FocusScope.of(context).requestFocus(FocusNode());
      },
      child: Scaffold(
        backgroundColor: YTStyle.bgColor,
        appBar: customAppBar(context, title: "待报价"),
        body: CustomScrollView(
          slivers: [
            //订单信息
            SliverToBoxAdapter(
              child: OrderInfo(),
            ),

            //询价信息
            SliverToBoxAdapter(
              child: Container(
                margin: EdgeInsets.only(top: setWidth(15)),
                padding: EdgeInsets.only(
                    top: setWidth(18),
                    left: setWidth(15),
                    bottom: setWidth(13)),
                decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border(
                        bottom: BorderSide(
                            color: Color(0xffF0F0F0), width: setWidth(0.5)))),
                child: Text(
                  "询价信息",
                  style: TextStyle(
                      color: Color(0xff323232),
                      fontSize: setSp(15),
                      fontWeight: FontWeight.w600),
                ),
              ),
            ),

            //报价列表
            SliverList(
                delegate: SliverChildBuilderDelegate(
              (context, index) {
                return _listItem();
              },
              childCount: 3,
            )),
            //放弃列表
            SliverList(
                delegate: SliverChildBuilderDelegate(
                      (context, index) {
                    return _listItem();
                  },
                  childCount: isShow?(typeList.length >0 ? typeList.length:0):0,
                )),
            //隐藏显示
            SliverToBoxAdapter(
              child: GestureDetector(
                behavior: HitTestBehavior.opaque,
                onTap: (){
                  setState(() {
                    isShow = !isShow;
                  });
                },
                child: Container(
                  alignment: Alignment.center,
                  margin: EdgeInsets.only(bottom: setWidth(20)),
                  padding: EdgeInsets.only(
                      top: setWidth(12),
                      bottom: setWidth(12)),
                  color: Colors.white,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Container(
                        child: Text(
                          isShow?"隐藏已放弃的${typeList.length-1}个商品":"已隐藏已放弃的${typeList.length-1}个商品",
                          style: TextStyle(
                              color: Color(0xff989898),
                              fontSize: setSp(14)),
                        ),
                      ),

                      Container(
                        margin: EdgeInsets.only(left: setWidth(6),right: setWidth(6)),
                        child: Text(
                          isShow?"收起": "展开",
                          style: TextStyle(
                              color: Color(0xff989898),
                              fontSize: setSp(14),
                              fontWeight: FontWeight.w600),
                        ),
                      ),
                      SizedBox(width: setWidth(12),
                        height: setWidth(6),
                        child: Image.asset(isShow?"assets/images/shouqi.png":"assets/images/zhankai.png",width: setWidth(12),
                          height: setWidth(6),fit: BoxFit.cover,),
                      ),

                    ],
                  ),
                ),
              ),
            ),

            //提交
            SliverToBoxAdapter(
              child: Container(
                alignment: Alignment.center,
                margin: EdgeInsets.only(
                    left: setWidth(15),
                    right: setWidth(15),
                    top: setWidth(44),
                    bottom: setWidth(44)),
                decoration: BoxDecoration(
                    color: YTTheme.theme,
                    borderRadius: BorderRadius.circular(4)),
                padding:
                    EdgeInsets.only(top: setWidth(13), bottom: setWidth(13)),
                child: Text(
                  "确认报价并提交",
                  style: TextStyle(
                      color: Colors.white,
                      fontSize: setSp(18),
                      fontWeight: FontWeight.w600),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }

  Widget _listItem() {
    return Container(
      color: Colors.white,
      padding: EdgeInsets.all(setWidth(15)),
      margin: EdgeInsets.only(bottom: setWidth(12)),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                height: setWidth(90),
                width: setWidth(90),
                decoration: BoxDecoration(
                    color: Color(0xffC4C4C4),
                    borderRadius: BorderRadius.circular(6)),
              ),
              SizedBox(
                width: setWidth(10),
              ),
              Expanded(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      child: Text(
                        "前挡泥板-右后翼子板",
                        style: TextStyle(
                            color: Color(0xff323232), fontSize: setSp(15)),
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                      ),
                    ),
                    SizedBox(
                      height: setWidth(5),
                    ),
                    Container(
                      child: Text(
                        "零件编号：50260TJFJ01",
                        style: TextStyle(
                            color: Color(0xff989898), fontSize: setSp(14)),
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                      ),
                    ),
                    SizedBox(
                      height: setWidth(19),
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Container(
                          child: Text("我的报价",
                              style: TextStyle(
                                  color: Color(0xff323232),
                                  fontSize: setSp(12))),
                        ),
                        SizedBox(
                          width: setWidth(5),
                        ),
                        Expanded(
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            crossAxisAlignment: CrossAxisAlignment.end,
                            children: [
                              Container(
                                width: setWidth(145),
                                height: setWidth(30),
                                child: TextField(
                                  textAlign: TextAlign.start,
                                  maxLines: 1,
                                  textInputAction: TextInputAction.done,
                                  style: TextStyle(
                                      fontSize: setSp(14),
                                      color: YTTheme.theme,
                                      fontWeight: FontWeight.w600),
                                  autofocus: false,
                                  inputFormatters: [
                                    WhitelistingTextInputFormatter(
                                        RegExp("[0-9.]")), //只允许输入小数
                                  ],
                                  decoration: InputDecoration(
                                    prefixText: "￥",
                                    contentPadding:
                                        EdgeInsets.only(top: setWidth(3)),
                                    enabledBorder: OutlineInputBorder(
                                      borderRadius: BorderRadius.circular(2.0),
                                      borderSide: BorderSide(
                                        color: Color(0xff989898),width: setWidth(0.5)
                                      ),
                                    ),
                                    focusedBorder: OutlineInputBorder(
                                      borderRadius: BorderRadius.circular(2.0),
                                      borderSide: BorderSide(
                                        color: Color(0xff989898),width: setWidth(0.5)
                                      ),
                                    ),
                                    hintStyle: TextStyle(
                                        color:YTTheme.theme,
                                        fontSize: setSp(16)),
                                  ),
                                ),
                              ),
                              Container(
                                child: Text("x1",
                                    style: TextStyle(
                                        color: Color(0xff323232),
                                        fontSize: setSp(14))),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                    SizedBox(
                      height: setWidth(35),
                    ),
                  ],
                ),
              ),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  Container(
                    margin: EdgeInsets.only(top: setWidth(6)),
                    child: Text(
                      "属性:",
                      style: TextStyle(
                          color: Color(0xff666666), fontSize: setSp(14)),
                    ),
                  )
                ],
              ),
              SizedBox(
                width: setWidth(5),
              ),
              //属性
              Expanded(
                  child: Container(
                child: Wrap(
                  spacing: setWidth(5),
                  runSpacing: setWidth(5),
                  children: typeList
                      .asMap()
                      .map((key, value) {
                        return MapEntry(key, GestureDetector(
                            onTap: (){
                              _selectType(context);
                            },
                            child: typeItem(key, value)));
                      })
                      .values
                      .toList(),
                ),
              )),
              //放弃
              GestureDetector(
                behavior: HitTestBehavior.opaque,
                onTap: () {},
                child: Container(
                  margin: EdgeInsets.only(top: setWidth(6)),
                  child: Row(
                    children: [
                      Container(
                        width: setWidth(15),
                        height: setWidth(15),
                        child: Image.asset(
                          "assets/images/fangqi.png",
                          fit: BoxFit.cover,
                        ),
                      ),
                      SizedBox(
                        width: setWidth(3),
                      ),
                      Container(
                        child: Text(
                          "放弃",
                          style: TextStyle(
                              color: Color(0xff999999), fontSize: setSp(13)),
                        ),
                      ),
                    ],
                  ),
                ),
              )
            ],
          )
        ],
      ),
    );
  }

  //选择属性
  Widget typeItem(int index, String title) {
    return Container(
      padding: EdgeInsets.only(
          top: setWidth(6),
          bottom: setWidth(6),
          left: setWidth(11),
          right: setWidth(11)),
      decoration: BoxDecoration(//未选中 F5F5F5
          color:Color(0xffF5FFFF),
          border: Border.all(color: YTTheme.theme, width: setWidth(0.5)),
          borderRadius: BorderRadius.circular(2)),
      child: Text(
        title,
        style: TextStyle(color: YTTheme.theme, fontSize: setSp(14)),
      ),
    );
  }

  //选择属性
  _selectType(BuildContext context){
    showModalBottomSheet(
        context: context,
        backgroundColor: Colors.white,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(10),
            topRight: Radius.circular(10),
          ),
        ),
        builder: (BuildContext context){
          return StatefulBuilder(
            builder: (BuildContext context,StateSetter state){
              return Stack(
                alignment: Alignment.topCenter,
                children: [
                  ListView.builder(
                      padding: EdgeInsets.only(top: setWidth(40)),
                      itemCount:typeList.length,
                      shrinkWrap: true,
                      itemBuilder: (context,index){
                        return GestureDetector(
                            behavior: HitTestBehavior.opaque,
                            onTap: (){
                              Navigator.pop(context);
                            },
                            child:  Container(
                              padding: EdgeInsets.only(top: setWidth(22),bottom: setWidth(22),),
                              margin: EdgeInsets.only(left: setWidth(10),right: setWidth(10)),
                              decoration: BoxDecoration(
                                  border: Border(bottom: BorderSide(color: Color(0xffF0F0F0),width: setWidth(0.5)))
                              ),
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Container(
                                    child: Text(typeList[index],style:TextStyle(color: Color(0xff333333),fontSize: setSp(15)),),
                                  ),
                                ],
                              ),
                            ));

                      }),
                  Container(
                    margin: EdgeInsets.only(top: setWidth(10)),
                    decoration: BoxDecoration(
                      color: Colors.white,
                        border: Border(bottom: BorderSide(color: Color(0xffF0F0F0),width: setWidth(0.5)))

                    ),

                    alignment: Alignment.center,
                    height: setWidth(40),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text("选择产品属性",style: TextStyle(color: Color(0xff333333),fontSize: setSp(17)),),
                      ],
                    ),
                  ),

                ],
              );
            },
          );
        }
    );
  }
}
